/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package ipfms.model;

import java.io.Serializable;
import javax.persistence.Basic;
import javax.persistence.Column;
import javax.persistence.Embedded;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.Table;

/**
 *
 * @author fikri
 */
@Entity
@Table(name = "user_role")
@NamedQueries({
    @NamedQuery(name = "PenggunaPeranan.findAll", query = "SELECT u FROM PenggunaPeranan u")})
public class PenggunaPeranan implements Serializable {
    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Basic(optional = false)
    @Column(name = "id_role")
    private Integer idRole;
    
    @ManyToOne
    @JoinColumn (name = "role_code")
    private KodPenggunaPeranan peranan;
    
    @ManyToOne
    @JoinColumn (name = "user_id")
    private Pengguna pengguna;
    
    
    @Embedded
    private InfoAudit infoAudit;
    
    public PenggunaPeranan() {
    }

    public PenggunaPeranan(Integer idRole) {
        this.idRole = idRole;
    }

    public PenggunaPeranan(Integer idRole, KodPenggunaPeranan roleCode) {
        this.idRole = idRole;
        this.peranan = roleCode;        
    }

    public Integer getIdRole() {
        return idRole;
    }

    public void setIdRole(Integer idRole) {
        this.idRole = idRole;
    }

    public Pengguna getPengguna() {
        return pengguna;
    }

    public void setPengguna(Pengguna pengguna) {
        this.pengguna = pengguna;
    }

    public KodPenggunaPeranan getPeranan() {
        return peranan;
    }

    public void setPeranan(KodPenggunaPeranan peranan) {
        this.peranan = peranan;
    }   

    public InfoAudit getInfoAudit() {
        return infoAudit;
    }

    public void setInfoAudit(InfoAudit infoAudit) {
        this.infoAudit = infoAudit;
    }    

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (idRole != null ? idRole.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof PenggunaPeranan)) {
            return false;
        }
        PenggunaPeranan other = (PenggunaPeranan) object;
        if ((this.idRole == null && other.idRole != null) || (this.idRole != null && !this.idRole.equals(other.idRole))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "ipfms.model.UserRole[ idRole=" + idRole + " ]";
    }
    
}
